import '../../constant/app_constant.dart';
import '../image/simple_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:page_indicator/page_indicator.dart';

/// 轮播图组件
class CarouselComponent extends StatelessWidget {
  /// 图片列表
  final List<String> images;

  const CarouselComponent({Key? key, required this.images}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return buildBody();
  }

  Container buildBody() {
    return Container(
      height: 150,
      margin: EdgeInsets.symmetric(horizontal: kDefaultPadded),
      child: PageIndicatorContainer(
        length: images.length,
        child: PageView(
          children: images.map(_builderItem).toList(),
        ),
      ),
    );
  }

  Widget _builderItem(String image) {
    return Container(
      child: SimpleImage(url: image,),
    );
  }
}
